import { watch } from "less";
import { defineStore } from "pinia";
import { ref, reactive } from "vue";
import { request } from '@/utils/axios/request.js'

export const useIndexStore = defineStore("index", () => {
  // 动态路由数据
  // 动态路由数据
  //普通成员
  let navRouter2 = reactive([
    {
      id: 1,
      title: "基础数据",
      role: 2,
      status: "正常",
      xiaoTu: "icon-qianshoushenpitongguo-xianxing",
      lieBiao: ["打卡详情", "员工假期详细", "工作日设置"],
      url: ["/clockingDetails", "/employeeLeaveDetails", "/workingday"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 3,
      title: "审批管理",
      role: 2,
      status: "正常",
      xiaoTu: "icon-shujuwajue",
      lieBiao: ["出差申请", "补卡申请", "请假申请", "加班申请"],
      url: [
        "/business",
        "/replacementCard",
        "/leaveRequest",
        "/applicationForExtraWork",
      ],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 5,
      title: "聊天室",
      role: 2,
      status: "正常",
      xiaoTu: "icon-queshengye_zanwushuju",
      lieBiao: ["公司聊天室"],
      url: ["/chat"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 4,
      title: "系统管理",
      role: 2,
      status: "正常",
      xiaoTu: "icon-xitongshezhi",
      lieBiao: ["菜单管理", "部门管理", "消息公告"],
      url: ["/menu", "/department", "/message"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
  ]);
  // 管理员
  let navRouter1 = reactive([
    {
      id: 1,
      title: "基础数据",
      role: 1,
      status: "正常",
      xiaoTu: "icon-qianshoushenpitongguo-xianxing",
      lieBiao: ["打卡详情", "员工假期详细", "工作日设置"],
      url: ["/clockingDetails", "/employeeLeaveDetails", "/workingday"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 2,
      title: "财务数据",
      role: 1,
      status: "正常",
      xiaoTu: "icon-caiwu-xianxing",
      lieBiao: ["工资详情"],
      url: ["/salary"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 3,
      title: "审批管理",
      role: 1,
      status: "正常",
      xiaoTu: "icon-shujuwajue",
      lieBiao: ["出差申请", "补卡申请", "请假申请", "加班申请"],
      url: ["/business", "/replacementCard", "/leaveRequest", "/applicationForExtraWork"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 5,
      title: "聊天室",
      role: 1,
      status: "正常",
      xiaoTu: "icon-queshengye_zanwushuju",
      lieBiao: ["公司聊天室"],
      url: ["/chat"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 4,
      title: "系统管理",
      role: 1,
      status: "正常",
      xiaoTu: "icon-xitongshezhi",
      lieBiao: ["菜单管理", "部门管理", "消息公告", "公司配置"],
      url: ["/menu", "/department", "/message", "/systemConfiguration"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
  ]);
  // 超级管理员
  let navRouter0 = reactive([
    {
      id: 1,
      title: "基础数据",
      role: 0,
      status: "正常",
      xiaoTu: "icon-qianshoushenpitongguo-xianxing",
      lieBiao: ["打卡详情", "员工假期详细", "工作日设置"],
      url: ["/clockingDetails", "/employeeLeaveDetails", "/workingday"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 2,
      title: "财务数据",
      role: 0,
      status: "正常",
      xiaoTu: "icon-caiwu-xianxing",
      lieBiao: ["工资详情"],
      url: ["/salary"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 3,
      title: "审批管理",
      role: 0,
      status: "正常",
      xiaoTu: "icon-shujuwajue",
      lieBiao: ["出差申请", "补卡申请", "请假申请", "加班申请"],
      url: ["/business", "/replacementCard", "/leaveRequest", "/applicationForExtraWork"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 5,
      title: "聊天室",
      role: 0,
      status: "正常",
      xiaoTu: "icon-queshengye_zanwushuju",
      lieBiao: ["公司聊天室"],
      url: ["/chat"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
    {
      id: 4,
      title: "系统管理",
      role: 0,
      status: "正常",
      xiaoTu: "icon-xitongshezhi",
      lieBiao: ["用户中心", "角色管理", "菜单管理", "部门管理", "消息公告", "公司配置", "系统日志"],
      url: ["/user", "/character", "/menu", "/department", "/message", "/systemConfiguration", "/systemlog"],
      times: "2022-1",
      isShow: false,
      isShow1: false,
      isShow2: true,
      shows: true,
    },
  ]);

  //权限字符
  let role = ref(2);
  // 修改权限字符方法
  let roleChange = async (username) => {
    try {
      let newdata = await request({
        url: `/admin/user/users1?username=${username}`,
        method: 'get'
      })
      role.value = newdata.data[0].role;
    } catch (err) {
      console.log(err);
    }
  };


  return {
    navRouter2,
    navRouter1,
    navRouter0,
    role,
    roleChange,
  };
});
